#include <algorithm>
#include <cstdio>
#include <queue>

const int N = 50005;
int n, k;
bool vis[N];
long long m;

struct Node {
  int p, q, id;
  inline bool operator<(const Node &rhs) const { return q < rhs.q; }
} a[N];

struct cmpP {
  inline bool operator()(const Node &lhs, const Node &rhs) { return lhs.p > rhs.p; }
};

struct cmpQ {
  inline bool operator()(const Node &lhs, const Node &rhs) { return lhs.q > rhs.q; }
};

struct cmpPQ {
  inline bool operator()(const Node &lhs, const Node &rhs) {
    return lhs.p - lhs.q > rhs.p - rhs.q;
  }
};

std::priority_queue<Node, std::vector<Node>, cmpP> Pq;
std::priority_queue<Node, std::vector<Node>, cmpQ> pQ;
std::priority_queue<Node, std::vector<Node>, cmpPQ> PQ;

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("shopping.in", "r", stdin);
  freopen("shopping.out", "w", stdout);
#endif
#endif

  scanf("%d%d%lld", &n, &k, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &a[i].p, &a[i].q);
    a[i].id = i;
    Pq.push(a[i]), pQ.push(a[i]);
  }
  std::sort(a + 1, a + n + 1);
  for (int i = 1; i <= std::min(n, k); ++i) {
    if (m >= a[i].q)
      m -= a[i].q, PQ.push(a[i]), vis[a[i].id] = true;
    else
      return printf("%d", i - 1), 0;
  }
  for (int i = k + 1; i <= n; ++i) {
    while (!Pq.empty() && vis[Pq.top().id]) Pq.pop();
    while (!pQ.empty() && vis[pQ.top().id]) pQ.pop();
    if (m + PQ.top().q - PQ.top().p - pQ.top().q >= m - Pq.top().p) {
      m = m + PQ.top().q - PQ.top().p - pQ.top().q, PQ.pop(), pQ.pop(),
      vis[pQ.top().id] = true;
    } else
      m -= Pq.top().p, vis[Pq.top().id] = true, Pq.pop();
    if (m < 0) {
      return printf("%d", i - 1), 0;
    }
  }
  printf("%d", n);
  return 0;
}